/*********************************************************************
 *
 *	Hardware specific definitions for:
 *    - %HUMAN_BOARD%
 *    - %SUPPORTED_PROCESSORS%
 *    - %NETWORK_INTERFACE%
 *
 *********************************************************************
 * FileName:        HardwareProfile.h
 * Dependencies:    Compiler.h
 * Processor:       PIC24F, PIC24H, dsPIC30F, dsPIC33F
 * Compiler:        Microchip C30 v3.24 or higher
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * Copyright (C) 2002-2010 Microchip Technology Inc.  All rights
 * reserved.
 *
 * Microchip licenses to you the right to use, modify, copy, and
 * distribute:
 * (i)  the Software when embedded on a Microchip microcontroller or
 *      digital signal controller product ("Device") which is
 *      integrated into Licensee's product; or
 * (ii) ONLY the Software driver source files ENC28J60.c, ENC28J60.h,
 *		ENCX24J600.c and ENCX24J600.h ported to a non-Microchip device
 *		used in conjunction with a Microchip ethernet controller for
 *		the sole purpose of interfacing with the ethernet controller.
 *
 * You should refer to the license agreement accompanying this
 * Software for additional information regarding your rights and
 * obligations.
 *
 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
 *
 *
 * Author               Date		Comment
 *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Howard Schlunder		09/16/2010	Regenerated for specific boards
 ********************************************************************/


#ifndef HARDWARE_PROFILE_H
#define HARDWARE_PROFILE_H

#include "Compiler.h"
#include <p24FJ128GA308.h>
// Define a macro describing this hardware set up (used in other files)
//#define %HARDWARE_BOARD%

// Set configuration fuses (but only in MainDemo.c where THIS_IS_STACK_APPLICATION is defined)

#if defined(THIS_IS_STACK_APPLICATION)

	#if defined(__PIC24FJ128GA308__)
		// PIC24FJ128GA308 PIM
                _CONFIG1 (WDTPS_PS32768 & FWPSA_PR128 & FWDTEN_WDT_DIS & ICS_PGx1& LPCFG_OFF & GWRP_OFF & GCP_OFF & JTAGEN_OFF )
                _CONFIG2 (POSCMD_NONE  & IOL1WAY_OFF & FCKSM_CSDCMD & FNOSC_FRC  & ALTVREF_ALT_AV_ALT_CV & OSCIOFCN_ON)                     //& BORV_BOR1_8 & OSCIOFCN_ON
                _CONFIG3 (WPFP_WPFP127 & SOSCSEL_ON & WDTWIN_PS25_0 & BOREN_ON & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM)
                _CONFIG4 (DSWDTPS_DSWDTPS1F & DSWDTOSC_LPRC & DSBOREN_OFF & DSWDTEN_OFF & DSSWEN_OFF )          //RTCBAT_ON & &  VBZPOR_ON

	// Watchdog timer off, ICD debugging on PGEC2/PGED2 pins, JTAG off, AVREF and CVREF in default locations
	#elif defined(__PIC24FJ256GB110__)
		// PIC24FJ256GB110 PIM
		_CONFIG2(PLLDIV_DIV2 & PLL_96MHZ_ON & FNOSC_PRIPLL & IOL1WAY_OFF & POSCMOD_XT); // Primary XT OSC with 96MHz PLL (8MHz crystal input), IOLOCK can be set and cleared
		_CONFIG1(JTAGEN_OFF & ICS_PGx2 & FWDTEN_OFF);									// Watchdog timer off, ICD debugging on PGEC2/PGED2 pins, JTAG off
	#elif defined(__PIC24FJ256GA110__)
		// PIC24FJ256GA110 PIM
		_CONFIG2(FNOSC_PRIPLL & IOL1WAY_OFF & POSCMOD_XT);	// Primary XT OSC with PLL, IOLOCK can be set and cleared
		_CONFIG1(JTAGEN_OFF & ICS_PGx2 & FWDTEN_OFF);		// Watchdog timer off, ICD debugging on PGEC2/PGED2 pins, JTAG off
	#elif defined(__PIC24F__)
		// All other PIC24F PIMs
		_CONFIG2(FNOSC_PRIPLL & POSCMOD_XT)		// Primary XT OSC with 4x PLL
		_CONFIG1(JTAGEN_OFF & FWDTEN_OFF)		// JTAG off, watchdog timer off
	#elif defined(__dsPIC33F__) || defined(__PIC24H__)
		// All dsPIC33F and PIC24H PIMs
		_FOSCSEL(FNOSC_PRIPLL)			// PLL enabled
		_FOSC(OSCIOFNC_OFF & POSCMD_XT)	// XT Osc
		_FWDT(FWDTEN_OFF)				// Disable Watchdog timer
		// JTAG should be disabled as well
	#endif


#endif


// Clock frequency values
// Create a PIC dependant macro for the maximum supported internal clock
#if defined(__PIC24F__) || defined(__PIC24FK__)
	#define MAXIMUM_PIC_FREQ		(32000000ul)
#else	// dsPIC33F, PIC24H
	#define MAXIMUM_PIC_FREQ		(80000000ul)
#endif

// These directly influence timed events using the Tick module.  They also are used for UART and SPI baud rate generation.
#define GetSystemClock()		(8000000)			// Hz
#define GetInstructionClock()	(4000000)	// Normally GetSystemClock()/4 for PIC18, GetSystemClock()/2 for PIC24/dsPIC, and GetSystemClock()/1 for PIC32.  Might need changing if using Doze modes.
#define GetPeripheralClock()	(4000000)	// Normally GetSystemClock()/4 for PIC18, GetSystemClock()/2 for PIC24/dsPIC, and GetSystemClock()/1 for PIC32.  Divisor may be different if using a PIC32 since it's configurable.

// Hardware I/O pin mappings
// LEDs
#define LED0_TRIS			(TRISGbits.TRISG7)	// Ref RG7 LED1
#define LED0_IO				(LATGbits.LATG7)
#define LED1_TRIS			(TRISGbits.TRISG8)	// Ref RG8 LED2
#define LED1_IO				(LATGbits.LATG8)
#define LED2_TRIS			(TRISBbits.TRISB9)
#define LED2_IO				(LATBbits.LATB9)
#define LED3_TRIS			(TRISBbits.TRISB8)	// No LED3 on this board
#define LED3_IO				(LATBbits.LATB8)
#define LED4_TRIS			(TRISAbits.TRISA10)	// No LED4 on this board
#define LED4_IO				(LATAbits.LATA10)
#define LED5_TRIS			(TRISAbits.TRISA9)	// No LED5 on this board
#define LED5_IO				(LATAbits.LATA9)
#define LED6_TRIS			(TRISBbits.TRISB7)	// No LED6 on this board
#define LED6_IO				(LATBbits.LATB7)
#define LED7_TRIS			(TRISBbits.TRISB6)	// No LED7 on this board
#define LED7_IO				(LATBbits.LATB6)
#define LED_GET()			(LED0_IO)
#define LED_PUT(a)                      (LED0_IO = (a))


// Momentary push buttons
#define BUTTON0_TRIS		(TRISDbits.TRISD12)      //  T1
#define	BUTTON0_IO			(PORTDbits.RD12)
#define BUTTON1_TRIS		(TRISDbits.TRISD13)     //  T2
#define	BUTTON1_IO			(PORTDbits.RD13)
#define BUTTON2_TRIS		(TRISDbits.TRISD6)     //   T3
#define	BUTTON2_IO			(PORTDbits.RD6)
#define BUTTON3_TRIS		(TRISAbits.TRISA1)	// No BUTTON3 on this board
#define	BUTTON3_IO			(1)

// LCD I/O pins
#define LCD_DATA0_TRIS		(TRISEbits.TRISE3)
#define LCD_DATA0_IO			(LATEbits.LATE3)
#define LCD_DATA1_TRIS		(TRISEbits.TRISE2)
#define LCD_DATA1_IO			(LATEbits.LATE2)
#define LCD_DATA2_TRIS		(TRISEbits.TRISE1)
#define LCD_DATA2_IO			(LATEbits.LATE1)
#define LCD_DATA3_TRIS		(TRISEbits.TRISE0)
#define LCD_DATA3_IO			(LATEbits.LATE0)

#define LCD_RD_WR_TRIS		(TRISGbits.TRISG6)
#define LCD_RD_WR_IO                    (LATGbits.LATG6)
#define LCD_RS_TRIS             (TRISCbits.TRISC3)
#define LCD_RS_IO			(LATCbits.LATC3)
#define LCD_E_TRIS		(TRISCbits.TRISC1)
#define LCD_E_IO			(LATCbits.LATC1)
//#define FOUR_BIT_MODE
// ENC28J60 I/O pins
#define ENC_RST_TRIS		(TRISBbits.TRISB15)	// Not connected by default
#define ENC_RST_IO			(LATBbits.LATB15)
#define ENC_CS_TRIS			(TRISDbits.TRISD14)
#define ENC_CS_IO			(LATDbits.LATD14)
#define ENC_SCK_TRIS		(TRISDbits.TRISD10)
#define ENC_SDI_TRIS		(TRISDbits.TRISD8)
#define ENC_SDO_TRIS		(TRISDbits.TRISD9)
#define ENC_SPI_IF			(IFS0bits.SPI1IF)//(PIR1bits.SSP1IF)
#define ENC_SSPBUF			(SPI1BUF)
#define ENC_SPISTAT			(SPI1STAT)
#define ENC_SPISTATbits		(SPI1STATbits)
#define ENC_SPICON1			(SPI1CON1)
#define ENC_SPICON1bits		(SPI1CON1bits)
#define ENC_SPICON2			(SPI1CON2)


#endif



